package com.supermarket.manage.common.validation;

import org.apache.commons.codec.binary.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author Faxon
 * @version 1.0
 * @date 2020-03-11 19:05
 **/
public class CodeModelValidator implements ConstraintValidator<CodeModel, String> {

    /**
     * 用户注册 模板id
     */
    public static final String REGISTER_CODE_MODEL = "SMS_185720087";

    /**
     * 用户登录 模板id
     */
    public static final String LOGIN_CODE_MODEL = "SMS_185720088";

    /**
     * 重置密码 模板id
     */
    public static final String PWD_CODE_MODEL = "SMS_184616822";

    /**
     * 用户绑定手机 模板id
     */
    public static final String BIND_MODEL = "SMS_185810880";

    /**
     * 通用 模板id
     */
    public static final String COMMON_CODE_MODEL = "SMS_185560691";

    private boolean require = false;

    @Override
    public void initialize(CodeModel constraintAnnotation) {
        require = constraintAnnotation.required();
    }

    @Override
    public boolean isValid(String modelId, ConstraintValidatorContext constraintValidatorContext) {
        if (modelId == null){
            return false;
        }
        if (require) {
            if (modelId.equals(REGISTER_CODE_MODEL) || modelId.equals(LOGIN_CODE_MODEL) || modelId.equals(BIND_MODEL)
                    || modelId.equals(PWD_CODE_MODEL) || modelId.equals(COMMON_CODE_MODEL)) {
                return true;
            }
        }
        return false;
    }
}
